//
//  ServerConfig.swift
//  Kool Car
//
//  Created by huangweiqiang on 2021/12/29.
//

import UIKit

//"siteUrl": "http://192.168.2.170:7480",
//"siteUrl": "http://it.xiantian365.com:27480",


private var kServerList = ["data": [
    [
        "siteUrl": "https://api.kc.com",
        "h5Url": "https://www.kc.com",
        "kafka": "",
        "uFlag": "",
        "name":""
    ],
    [
        "siteUrl": "http://it.xiantian365.com:12033",
        "h5Url": "http://it.xiantian365.com:12035",
        "kafka": "",
        "uFlag": "",
        "name":"外网测试环境"
    ],
    
    [
        "siteUrl": "http://192.168.2.178:7491",
        "h5Url": "",
        "kafka": "",
        "uFlag": "",
        "name":"开发环境"
    ],
    
    [
        "siteUrl": "http://www.kc.com:12019",
        "h5Url": "",
        "kafka": "",
        "uFlag": "",
        "name":"预发布环境"
    ],
    
    [
        "siteUrl": "http://192.168.2.178:7490",
        "h5Url": "",
        "kafka": "",
        "uFlag": "",
        "name":"验证环境"
    ],
    
    
    [
        "siteUrl": "http://192.168.2.170:7480",
        "h5Url": "http://it.xiantian365.com:12035",
        "kafka": "",
        "uFlag": "",
        "name":"内网测试环境"
    ]
  
]]

private var kCompany_advadge_simple = """
    <div style="width:100%;">
            <h4 style="text-decoration:underline;">公司优势</h4>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/11912AF014DD5647CCA41650B9D41C24_1653126131850.png" />
            </div>
            <p style="width:100%; text-align: center;font-size: 16px;">卖车快捷方便，设有车价保证承诺</p>
            <p style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;客户提交放售车辆的资料后，保证24小时内获专人快速报价。客户享有车价保证承诺，保障卖车客户利益。亦享有专人代办车辆赎会，更改登记及处理一切相关文件。</p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F0FA1D41B7CCE2D838408A781DEAF8C7_1653126438013.png" />
            </div>
            <p style="width:100%; text-align: center;">车辆优质保证</p>
            <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;每辆出售的汽车都经过精挑细选，不仅出厂年份和行车里程都会详细查核，我们坚决拒绝事故车、泡
              水车和来路不明之车辆。</p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F340AC68C8138BBE67D0E0D56FE89398_1653126547565.png" />
            </div>
            <p style="width:100%; text-align: center;">专业维修服务</p>
            <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以优惠价格收费提供专业的一站式汽车维修服务。如需了解更多，请参閲服务详情或与我们的销售专
              员联络。</p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/A1E8AC2E711708F3CF4DF0FAEECD9321_1653126561993.png" />
            </div>
            <p style="width:100%; text-align: center;">专人一站式跟进</p>
            <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所有汽车买卖及维修服务全程由专人跟进，可因应您的需求推荐最合适的车款，并安排代办财务、汽
              车保险、车辆赎会及汽车过户等事宜。</p>
          </div>
"""

private var kCompany_advadge_en = """
    <div style="width:100%;">
            <h4 style="text-decoration:underline;">CompetitiveEdge</h4>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/11912AF014DD5647CCA41650B9D41C24_1653126131850.png" />
            </div>
            <p style="width:100%; text-align: center;font-size: 16px;">Provide a Guaranteed Price and Quick and Easy Car
              Selling Procedure</p>
            <p style="font-size: 16px;line-height: 24px;">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              Customers who properly submitted the selling car information will be in touch with our specialist and received
              a quotation within 24 hours. A price guarantee commitment is also available to protect customers. Our
              specialist will take care of vehicle redemption, change of registration and all such related documentation.
            </p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F0FA1D41B7CCE2D838408A781DEAF8C7_1653126438013.png" />
            </div>
            <p style="width:100%; text-align: center;">Vehicle Quality Assurance </p>
            <p style="font-size: 16px;line-height: 24px;">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Every vehicle we sell has been carefully selected. Aside from meticulously
              inspecting vehicles and their manufacturing year and mileage, we will never accept cars that have been
              involved in accidents, flooded vehicles or those from unknown origins.</p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F340AC68C8138BBE67D0E0D56FE89398_1653126547565.png" />
            </div>
            <p style="width:100%; text-align: center;">Professional Maintenance Services</p>
            <p style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              We provide specialized all-inclusive maintenance services at a competitive price. Please visit the “Our
              Services” section or contact our specialist directly for more information.</p>
            <div style="text-align: center;">
              <img style="width:60px; height:60px; border-radius: 50px;"
                src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/A1E8AC2E711708F3CF4DF0FAEECD9321_1653126561993.png" />
            </div>
            <p style="width:100%; text-align: center;">Specialist Follow-up</p>
            <p style="font-size: 16px;line-height: 24px;">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A specialist will be assigned to assist each customer to provide personalized
              and professional services. We will provide the best car recommendation upon your budget and need and assist
              with loan and insurance applications, vehicle redemption, and license transfer-related matters.</p>
          </div>
"""

private var kCompany_advadge_hk = """
    <div style="width:100%;">
        <h4 style="text-decoration:underline;"> 公司優勢</h4>
        <div style="text-align: center;">
          <img style="width:60px; height:60px; border-radius: 50px;"
            src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/11912AF014DD5647CCA41650B9D41C24_1653126131850.png" />
        </div>
        <p style="width:100%; text-align: center;font-size: 16px;">賣車快捷方便，設有車價保證承諾</p>
        <p style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;客戶提交放售車輛的資料後，保證24小時內獲專人快速報價。客戶享有車價保證承諾，保障賣車客戶利益。亦享有專人代辦車輛贖會，更改登記及處理一切相關文件。</p>
        <div style="text-align: center;">
          <img style="width:60px; height:60px;"
            src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F0FA1D41B7CCE2D838408A781DEAF8C7_1653126438013.png" />
        </div>
        <p style="width:100%; text-align: center;">車輛優質保證</p>
        <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;每輛出售的汽車都經過精挑細選，不僅出廠年份和行車里程都會詳細查核，我們堅決拒絕事故車、泡
          水車和來路不明之車輛。</p>
        <div style="text-align: center;">
          <img style="width:60px; height:60px; border-radius: 50px;"
            src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/F340AC68C8138BBE67D0E0D56FE89398_1653126547565.png" />
        </div>
        <p style="width:100%; text-align: center;">專業維修服務</p>
        <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以優惠價格收費提供專業的一站式汽車維修服務。如需了解更多，請參閲服務詳情或與我們的銷售專
          員聯絡。</p>
        <div style="text-align: center;">
          <img style="width:60px; height:60px; border-radius: 50px;"
            src="https://koolcar-test.oss-cn-shenzhen.aliyuncs.com/other/202205/20220521/A1E8AC2E711708F3CF4DF0FAEECD9321_1653126561993.png" />
        </div>
        <p style="width:100%; text-align: center;">專人一站式跟進</p>
        <p  style="font-size: 16px;line-height: 24px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所有汽車買賣及維修服務全程由專人跟進，可因應您的需求推薦最合適的車款，並安排代辦財務、汽
          車保險、車輛贖會及汽車過戶等事宜。</p>
      </div>
"""

class ServerConfig {
    static let shared = ServerConfig()
    ///获取服务数据
    func getServerList() -> [ServerModel] {
        let jsonStr = self.getServerJson(jsonKey: kServerList)
        if jsonStr == "" {
            return []
        }
        let serverData = ServerResModel.init(JSONString: jsonStr)
        return serverData?.data ?? []
    }
    
    ///生成jsonStr
    private func getServerJson(jsonKey: Any) -> String{
        do {
            if let jsonData = try? JSONSerialization.data(withJSONObject: jsonKey, options: []){
                let jsonString = String.init(data: jsonData, encoding: .utf8)
                return jsonString ?? ""
            }
        }
        return ""
    }
    
    ///获取请求的url
    public static func requestUrl() -> String {
        var siteUrl = XTManageCenter.getLocalStringDataValue(aKey: UtilCenter.siteUrl)
        if siteUrl == "" {
            siteUrl = ServerConfig.shared.getServerList().first?.siteUrl ?? ""
        }
        return siteUrl
    }
    
    ///获取请求的url
    public static func requestH5Url() -> String {
        var h5Url = XTManageCenter.getLocalStringDataValue(aKey: UtilCenter.h5Url)
        if h5Url == "" {
            h5Url = ServerConfig.shared.getServerList().first?.h5Url ?? ""
        }
        return h5Url
    }
    
    ///公司优势
    func getCompanyAdvadge() -> String {
        let localSet = XTManageCenter.getLocalStringDataValue(aKey: UtilCenter.kAppLanguage)
        if localSet.contains("en") {
            return kCompany_advadge_en
        }else if localSet.contains("zh") {
            return kCompany_advadge_simple
        }else{
            return kCompany_advadge_hk
        }
    }
}

